A = [3, 2, 1, 2, 1, 7]

# 排序，使后一个比前一个大1即可


res = 0
A.sort()
for i in range(1, len(A)):
    if A[i] <= A[i - 1]:
        res = res + A[i - 1] - A[i] + 1
        A[i] = A[i] + A[i - 1] - A[i] + 1

print(res)
